/**
 * CopyRight © 2012 USTC SINOVATE SOFTWARE CO.LTD All Rights Reserved.
 */

package com.cmcc.zysoft.spring.security.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import com.cmcc.zysoft.infocollection.common.BaseController;
import com.cmcc.zysoft.infocollection.constant.Constant;
import com.cmcc.zysoft.spring.security.jxl.JXLSExcelView;
import com.cmcc.zysoft.spring.security.service.ExportExcelService;

/**
 * @author 袁凤建
 * <br />邮箱: yuan.fengjian@ustcinfo.com
 * <br />描述: ExportExcelController.java
 * <br />版本: 1.0.0
 * <br />日期: 2013-9-29 下午2:51:38
 * <br />CopyRight © 2012 USTC SINOVATE SOFTWARE CO.LTD All Rights Reserved.
 */

@Controller
public class ExportExcelController extends BaseController {

	/**
	 * 属性名称: exportExcelService.
	 * 类       型: ExportExcelService.
	 */
	@Resource
	private ExportExcelService exportExcelService;
	
	@RequestMapping("/exportExcel")
	public void opt(String exportFileName, String templateFileName, HttpServletRequest request, HttpServletResponse response){
		Map<String, Object> map = new HashMap<String, Object>();
		List<Map<String,Object>> list = this.exportExcelService.getExportData();
		HttpSession session = request.getSession();
		String time1 = (String)session.getAttribute(Constant.EXPORT_EXCEL_TIME1);
		String time2 = (String)session.getAttribute(Constant.EXPORT_EXCEL_TIME2);
		map.put("oldTime1", time1);
		map.put("oldTime2", time2);
		map.put("records", list);
		map.put("ExcelExportFileName", exportFileName);
		map.put("ExcelTemplateFileName", templateFileName);
		try {
			JXLSExcelView jXLSExcelView = new JXLSExcelView();
			jXLSExcelView.render(map, request, response);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}